home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Comm / irc / Mail.lha / Mail.amirx next >
Text File  |  2004-07-18  |  3KB  |  121 lines

  1. /* Mail.amirx (12.07.04) ©2004 Michael Trebilcock */
  2. Parse Arg Args
  3. Args2=Upper(Args)
  4.  
  5. Parse Var Args2 CMD" "CMD2" "CMD3
  6. CR="0D"x
  7.  
  8. /* Configuration */
  9. User="youneed" /* Your login name */
  10. Pass="tofill" /* Your password */
  11. POP3="" /* POP3 address */
  12. Port="theseout" /* POP3 port number */
  13. /* End Configuration */
  14.  
  15. IF POP3="" THEN Call cEcho("You need to configure this script before you can use it",1)
  16.  
  17. Call cEcho("Connecting to mail server...")
  18. IF ~Open(TCP,"TCP:"POP3"/"Port,"RW") THEN DO;Call cEcho("Can't connect to "POP3"...");Exit;End
  19. Call cEcho("Connected, awaiting welcome message...")
  20. IF Word(ReadLn(TCP),1)~="+OK" THEN Call cEcho(POP3 "is not a mail server.",1)
  21. Call cEcho("Sending user ID...")
  22. Call WriteLn(TCP,"USER "User)
  23. IF Word(ReadLn(TCP),1)~="+OK" THEN Call cEcho("Invalid user ID...",1)
  24. Call cEcho("Sending password...")
  25. Call WriteLn(TCP,"PASS "Pass)
  26. IF Word(ReadLn(TCP),1)~="+OK" THEN Call cEcho("Invalid password...",1)
  27. IF CMD="DEL" THEN DO
  28.  IF CMD2="ALL" THEN DO
  29.   Call GStat()
  30.   IF Amount="0" THEN Call cEcho("You have no emails to delete...",1)
  31.   IF CMD3="" THEN CMD3=Amount
  32.   Args="DEL"
  33.   DO i=1 TO CMD3
  34.    Args=Args" "i
  35.   End
  36.  End
  37.  Amount=SubStr(Args,5)
  38.  DO i=1 TO Words(Amount)
  39.   Call WriteLn(TCP,"DELE "Word(Amount,i))
  40.   IF Word(ReadLn(TCP),1)~="+OK" THEN DO;Call cEcho("Couldn't delete email "Word(Amount,i)"...");End
  41.   ELSE DO;Call cEcho("Deleted email "Word(Amount,i)"...");End
  42.  End
  43.  Call Disconn()
  44. End
  45. Call cEcho("Getting statistics...")
  46. Call GStat()
  47. IF Amount="0" THEN Call cEcho("You have no new emails...",1)
  48. Call cEcho("You have "Amount" new email(s), "Bytes" bytes total...")
  49.  
  50. IF CMD="VERBOSE" THEN DO
  51.  Call WriteLn(TCP,"LIST")
  52.  IF Word(ReadLn(TCP),1)~="+OK" THEN Call cEcho("Unable to grab byte sizes...",1)
  53.  i=1
  54.  Output=Strip(ReadLn(TCP),,CR)
  55.  DO UNTIL Output="."
  56.   LIST.i=Word(Output,2)
  57.   Output=Strip(ReadLn(TCP),,CR)
  58.   i=i+1
  59.  End
  60.  DO i=1 TO Amount
  61.   drop From
  62.   drop Subject
  63.   drop Attaches
  64.   Call WriteLn(TCP,"TOP "i" 1")
  65.   IF Word(ReadLn(TCP),1)~="+OK" THEN Call cEcho("Unable to grab email information...",1)
  66.   DO UNTIL Output="."
  67.    Output=Strip(ReadLn(TCP),,CR)
  68.    UOut=Word(Upper(Output),1)
  69.    IF UOut="FROM:" THEN From=SubStr(Output,7)
  70.    IF UOut="SUBJECT:" THEN Subject=SubStr(Output,10)
  71.    IF UOut="CONTENT-TYPE"&Word(Output,2)="multipart/mixed;" THEN Attaches="yes"
  72.   End
  73.   IF From=""|From="FROM" THEN From="<unknown> "
  74.   IF Subject=""|Subject="SUBJECT" THEN Subject="<unknown> "
  75.   IF Attaches=""|Attaches="ATTACHES" THEN Attaches="no"
  76.   Call cEcho(""i". From: "DecISO(From)"  Subject: "DecISO(Subject)"  Size: "LIST.i"  Attachment(s): "Attaches)
  77.  End
  78. End
  79.  
  80. Call Disconn()
  81.  
  82. cEcho:
  83. "ECHO P="d2c(27)"b«Mail» "Arg(1)
  84. IF Arg(2)="1" THEN Call Disconn()
  85. Return 0
  86.  
  87. Disconn:
  88. Call cEcho("Disconnecting...")
  89. Call WriteLn(TCP,"QUIT")
  90. Call Close(TCP)
  91. Exit
  92.  
  93. GStat:
  94. Call WriteLn(TCP,"STAT")
  95. Output=Strip(ReadLn(TCP),,CR)
  96. IF Word(Output,1)~="+OK" THEN Call cEcho("Unable to get statistics...",1)
  97. Parse Var Output Ok" "Amount" "Bytes
  98. Return 0
  99.  
  100. DecISO:
  101. Text=Arg(1)
  102. DO UNTIL First=Text
  103.  Parse Var Text First"=?"Header"?"Type"?"Encode"?="Rest
  104.  IF Type="Q" THEN DO 
  105.   Text2=""
  106.   DO UNTIL Encode2=""
  107.    Parse Var Encode First2"="Encode2
  108.    Encode3=x2c(Left(Encode2,2))
  109.    Text2=Text2""First2""Encode3
  110.    Encode=SubStr(Encode2,3)
  111.   End
  112.   Text=First""Text2""Rest
  113.  End
  114.  ELSE First=Text
  115. End
  116. Return Text
  117.  
  118. Syntax:
  119. Call cEcho("Command on line" SIGL "returned" RC ":" errortext(rc) sourceline(SIGL))
  120. Exit
  121.